package homework4;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @classname:NewWork
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/15 20:10
 * @version: 0.1
 * @since:1.8
 */
public class NewWork {
    public static void main(String[] args) {
        Set<Student> students = new HashSet<>(16);
        ThreadLocalRandom random = ThreadLocalRandom.current();

        for(;students.size()<20;){
            students.add(new Student(random.nextInt(1,41),random.nextInt(  0,101)));
        }
        students.forEach(System.out::println);

        //set-->list通过构造方法
//        ArrayList<Student> students1 = new ArrayList<>(students);
//        Collections.sort(students1,Comparator.comparing(Student::getScore));
//        System.out.println("-------");
//        System.out.println(students1.get(0));
//        System.out.println(students1.get(students1.size()-1));

        //获得对象的stream对象  流对象只能操作一次   所以对stream操作的时候多数使用链式写法
        //stram获得最大值和最小值
        Optional<Student> min = students.parallelStream().min(Comparator.comparing(Student::getScore));
        //Optional-->Student   get()
        System.out.println(min.get());
        Optional<Student> max = students.parallelStream().max(Comparator.comparing(Student::getScore));
        System.out.println(max);
        //通过stream来进行排序
        System.out.println("---------------");


    }
}
